package vm;

import javafx.beans.property.SimpleStringProperty;

/**
 * Atminties žodis
 * @author Paulius Dambrauskas
 */
public class Word {
    public SimpleStringProperty wordValue;
    public SimpleStringProperty virtualAddress;
    public SimpleStringProperty address;
    
    private Boolean reservStatus = false;
    
    public Word(int address, String word){
         this.wordValue = new SimpleStringProperty(word);
         this.address = new SimpleStringProperty(formatAddress(toHex(address)));
         this.virtualAddress = new SimpleStringProperty();
    }
    
    public void setReservStatus(Boolean status) {
        reservStatus = status;
    }
    
    public Boolean getReservStatus() {
        return reservStatus;
    }
    
    public SimpleStringProperty wordValueProperty(){
        return wordValue;
    }
    
    public SimpleStringProperty addressProperty(){
        return address;
    }
    
    public SimpleStringProperty virtualAddressProperty(){
        return virtualAddress;
    }
    private String toHex(int s){
        return Integer.toHexString(s);
    }
    public void setVirtualAddressValue(int value){
        this.virtualAddress.set(formatAddress(toHex(value)));
    }
    private String formatAddress(String s){
        return ("0000" + s).substring(s.length()).toUpperCase();
    }
}
